package com.unism.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import com.unism.enums.Twice;


@Converter(autoApply = true)
public class TwiceConverter implements AttributeConverter<Twice, Integer> {

	@Override
	public Integer convertToDatabaseColumn(Twice twice) {
		switch (twice) {
		case FARMER:
			return 1;
		case COOP:
			return 2;
		default:
			throw new IllegalArgumentException("Unknown value: " + twice);
		}
	}
	
	@Override
	public Twice convertToEntityAttribute(Integer dbData) {
		switch (dbData) {
		case 1:
			return Twice.FARMER;
		case 2:
			return Twice.COOP;
		default:
			throw new IllegalArgumentException("Unknown value: " + dbData);
		}
	}

}
